file_copy
This function copies a given file.
bool file_copy(string source, string destination, bool overwrite)
Parameters:
source
The name of the file to copy.
destination
The name of the file to copy to.
overwrite
A boolean specifying whether the source file should be overwritten (see remarks).
Return value:
true on success, false on failure.
Remarks:
Situations in which this function may return false could include:
- The source file does not exist. In this case the function will set the last error flag to -15.
- The destination filename references a directory that does not exist. In this case the last error flag will be set to -30.
- The overwrite flag is set to false and the destination exists. In this case the last error flag will be set to -35.
A file copied with this function inherits all the attributes of the source file.
This function works with both absolute and relative paths.
Example:
// Copy the file C:\test.txt.
void main()
{
if(file_copy("C:\\test.txt", "c:\\test_copy.txt", false))
{
alert("Information", "The file was copied successfully.");
}
else
{
alert("Error", "The file could not be copied.\nReason: " + get_last_error_text());
}
}